<?php
if(!defined('SYSTEM_PATH' ) ) die('Cannot access this page directly or see your configuration file ' ) ;
/**
*
* @author menTiss
* @desc Base class result
* @version 1.0
* @date 23/10/2007
*/
class Result extends Cosmo {
	public $_idQuery = false ;
	private $_counter = 0 ;

	/**
	 * Result::__construct()
	 *
	 */
	public function __construct($id = null) {
		parent::__construct() ;
		if(get_class($this) == 'Result') {
			// This should not happen and is forbidden !
			$this->shutdown('The class Result cannot be called directly') ;
		}
		if(!is_null($id)) 
			$this->setIdQuery($id) ;
		$this->_init() ;
	}
	/**
	 * mysqlResult::__call()
	 * 
	 * @desc Allow to execute an abstract method from a child object
	 * 
	 * @param string $methodCalled
	 * @param mixed $parameters
	 * 
	 * @return mixed
	 */
	public function __call($methodCalled, $parameters) {
		if(ereg('getResultBy',$methodCalled)) {
			$commande = strtolower(trim(substr($methodCalled,11))) ;
			if(method_exists($this,'result_'.$commande))
				return call_user_func(array($this, 'result_'.$commande),'');
		}
		if(ereg('getNumberOf',$methodCalled)) {
			$commande = strtolower(trim(substr($methodCalled,11))) ;
			if(method_exists($this,'num_'.$commande)) {
				return call_user_func(array($this, 'num_'.$commande),'');
			}			
		}
		return false ;
	}
	/**
	 * Result::setIdQuery()
	 *
	 * @param mixed $idQuery
	 * @return
	 */
	final public function setIdQuery($idQuery) {
		if(!is_resource($idQuery))
			return false;

		$this->_idQuery = $idQuery ;
		return true;
	}
	/**
	 * Result::free()
	 *
	 * @return
	 */
	final public function free() {
		unset($this) ;
	}
	/**
	 * Result::__destruct()
	 *
	 */
	public function __destruct() {
		$this->free() ;
	}
	/**
	 * Result::setCounter()
	 *
	 * @param mixed $number
	 * @return
	 */
	public function setCounter($number) {
		if(!is_numeric($number))
			return false ;
		$this->_counter = $number ;
		return true ;
	}
	/**
	 * Result::getCounter()
	 *
	 * @return
	 */
	public function getCounter() {
		return $this->_counter;
	}
	/**
	 * Result::setCounterAtBegin()
	 *
	 * @return
	 */
	public function setCounterAtBegin() {
		$this->_counter = 0 ;
	}
	/**
	 * Result::setCounterAtEnd()
	 *
	 * @return
	 */
	public function setCounterAtEnd() {
		$this->_counter = $this->getNumberOfRows()-1 ;
	}
}

?>